<!--
 * @Description: 关于我们页面组件，未完成
 -->
<template>
  <div class="goods" id="about" name="about">
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <template v-for="seckiltime in seckilTimeList">
        <el-menu-item :index="seckiltime.seckildate_id.toString()" :key="seckiltime.seckildate_id">
          {{ seckiltime.start_time + " - " + seckiltime.end_time }}
        </el-menu-item>
      </template>
    </el-menu>
    
    <!-- 主要内容区 -->
    <div class="main">
      <div class="list">
        <MyList :list="product" isSeckil="1" v-if="product.length > 0"></MyList>
        <div v-else class="none-product">
          抱歉没有找到相关的商品，请看看其他的商品
        </div>
      </div>
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="pageSize"
          :total="total"
          @current-change="currentChange"
        ></el-pagination>
      </div>
      <!-- 分页END -->
    </div>
    <!-- 主要内容区END -->
  </div>
</template>
<script>
import { findAllSeckil,findAllSeckildate } from '../api/seckil';
export default {
  name: "about",
  data() {
    return {
      activeIndex: '1',
      // 秒杀时间段数组
      seckilTimeList: [],
      form: {
        seckildate_id: 0
      },
      product: [], // 商品列表
      total: 0, // 商品总量
      pageSize: 15, // 每页显示的商品数量
    }
  },
  activated() {
    if (this.seckilTimeList.length == 0) {
      this.getAllSedkilTime();
    }
  },
  methods: {
    //   获取所有的秒杀时间段
    getAllSedkilTime() {
      findAllSeckildate().then(res => {
        this.seckilTimeList = res;
        console.log(this.seckilTimeList)
        this.getSeckilGoods(res[0].seckildate_id)
      });
    },
    // 时间段切换
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
      this.getSeckilGoods(key)
    },
    // 通过秒杀时间段 查找秒杀商品
    getSeckilGoods(id) {
      this.form.seckildate_id = id
      findAllSeckil(this.form).then(res => {
        console.log(res)
        this.product = []
        for (let i = 0; i < res.length; i++) {
          this.product.push(res[i].goods)
        }
        console.log(this.product)
      })
    },
    // 页码变化调用currentChange方法
    currentChange(currentPage) {
      this.currentPage = currentPage;
      if (this.search != "") {
        this.getProductBySearch();
      } else {
        this.getData();
      }
      this.backtop();
    },
  }
};
</script>

<style scoped>
.el-menu-demo {
  width: 80%;
  margin: 0 auto;
  background-color: whi;
}
.el-menu-demo > li {
  width: 25%;
  text-align: center;
}

.about {
  background-color: #f5f5f5;
}
.about .about-header {
  height: 64px;
  background-color: #fff;
  border-bottom: 2px solid #ff6700;
}
.about .about-header .about-title {
  width: 1225px;
  margin: 0 auto;
  height: 64px;
  line-height: 64px;
  font-size: 28px;
}
.about .content {
  padding: 20px 0;
  width: 1225px;
  margin: 0 auto;
}
.about .content .goods-list {
  margin-left: -13.7px;
  overflow: hidden;
}
.about .about-content {
  width: 1225px;
  margin: 0 auto;
  background-color: #fff;
}

.goods {
  background-color: #f5f5f5;
}

/* 主要内容区CSS */
.goods .main {
  margin: 0 auto;
  max-width: 1225px;
}
.goods .main .list {
  min-height: 650px;
  padding-top: 14.5px;
  margin-left: -13.7px;
  overflow: auto;
}
.goods .main .pagination {
  height: 50px;
  text-align: center;
}
.goods .main .none-product {
  color: #333;
  margin-left: 13.7px;
}
/* 主要内容区CSS END */
</style>
